package com.study.d2_file;

import java.io.File;

public class Test5 {
    public static void main(String[] args) {
        //文件搜索
        File file = new File("C:\\Users\\51230\\Desktop");
        searchFile(file,"移动Webday05.pdf");
    }

    private static void searchFile(File dir,String s) {
        if(dir==null||!dir.exists()||dir.isFile()){
            return;
        }
        File[] files = dir.listFiles();
        if(files==null||files.length==0){
            return;
        }
        for (File file : files) {
            if(file.isFile()){
                if(file.getName().contains(s)){
                    System.out.println(file.getAbsolutePath());
                }
            }else{
                searchFile(file,s);
            }
        }
    }
}
